package net.babelphish.altitudesig;

import java.util.ArrayList;

import com.google.gson.*;

class GameTypeData {
	
	protected Integer rank;
	protected String badge;
	protected String rankname;
	protected Integer rating;
	protected ArrayList<Double> ratings;
	protected Integer wins;
	protected Integer losses;
			
	GameTypeData() {

	}
}

class UserData  {
	protected String username;
	//private String vaporid;
	protected GameTypeData tbd_5v5;
	protected GameTypeData ball_6v6;
	
	UserData() {
		//no-args constructor
	}
}


public class JSONScraper extends DataScraper {

	
	public JSONScraper(String dataLocation) {
		super(dataLocation);
	}

	@Override
	boolean processScrapedData(StringBuilder scrapedData, GAME_TYPE gameType) {
		Gson gson = new Gson();		
		UserData parsedData = gson.fromJson(scrapedData.toString(), UserData.class);
		this._playerName = parsedData.username;
		GameTypeData gamesData;
		if (gameType == GAME_TYPE.BALL) {
			gamesData = parsedData.ball_6v6;
		} else if (gameType == GAME_TYPE.TBD) {
			gamesData = parsedData.tbd_5v5;
		} else {
			return false;
		}
			
		this._rank = gamesData.rank;
		this._rating = gamesData.rating;
		this._winLoss = gamesData.wins.toString() + " - " + gamesData.losses.toString();
		this._ratings = gamesData.ratings;		
		
		return true;
	}

}
